$(function () {
    window.$containerObj = {
        main: $('#container'),  // container元素
        data: {}, // hospital、type、assets、year数据
        init: function () {
            this.queryMin = '';
            this.queryMax = '';
            this.totalObj.init(); // 初始化 概览框 对象
            this.chartObj.init(); // 初始化 echart 对象
            this.modalObj.init(); // 初始化 详情模态框 对象
        },
        /* 查询hospital、type、assets、year数据 */
        queryData: function (tag, params, fn) { // tag: hospital、type、assets、year, params: 筛选条件, fn: 回调函数
            var $this = this;
            var url = basePath + 'charts/area/cost/' + tag;
            publicAjax(url, 'post', $.extend({}, $headerObj.searchObj.params, params || {}, params), function (data) {
                $this.data[tag] = data.data || {list: []};  // 设置$containerObj对象data数据
                ($this.data[tag].list || []).calTotal().sortByKey(tag === 'assets' ? 'amount' : 'jnAssetsAmount');  // 计算总数，按照curPrice排序
                // 设置模态框数据
                $this.modalObj.data[tag] = $.extend(true, {}, $this.data[tag]);
                if (fn) {fn();} else {
                    if (tag === 'model') {  // 设置echart图表数据
                        $this.chartObj.convertData(); // chartObj转换echart所用数据
                        $this.chartObj.setChart();  // chartObj设置echart图表
                    }
                    // 获取数据长度，用于计算TOP5显示条数
                    var length = tag === 'type'
                        ? $this.data[tag].list[-1].list ? $this.data[tag].list[-1].list.length : 0
                        : $this.data[tag].list.length;
                    $this.top5Obj.convertData(tag, 0, length > 5 ? 5 : length); // top5Obj转化数据，及设置TOP5列表
                    /* 如果模态框显示则刷新模态框数据 */
                    if ($this.modalObj.main.is(':visible') || $this.modalObj.yearMain.is(':visible')) {
                        $this.modalObj.setModal($this.modalObj.main.data().tag, 'curPrice', 'desc');
                    }
                }
            }, true);
        },
        /* 点击TOP5列表及详情模态框跳转关系 */
        query: function (tag, id) {
            var $this = this;
            if (tag === 'hospital') { // 如果是医院就跳转到医院报表
                window.open(basePath + 'charts/hospital/model-cost/page?hospitalId=' + id);
            } else if (tag === 'model') {  //
                this.modalObj.queryAssetsTable('assets', {modelName: id});
                this.modalObj.assetsMain.iziModal('setTitle', '设备详情');
            } else if (tag === 'assets') {  // 如果是具体设备就跳转到设备详情页面
                window.open(basePath + 'charts/overview/assets/page?deviceId=' + id);
            } else if (tag === 'year') {  // 如果是月份显示，筛选年份数据
                this.queryData('model', {monthId: id}, function () {
                    $this.modalObj.setModal('model', 'jnAssetsAmount', 'desc', ',monthId:' + id);
                });
            }
        }
    };
    /* 概览框对象 */
    $containerObj.totalObj = {
        main: $containerObj.main.find('.main-total'), // 概览框元素
        data: {}, // 概览框数据
        init: function () {
            this.queryData(); // 查询概览框数据
        },
        /* 查询概览框数据 flag：点击气泡时，传true，只查询除气泡图以外的数据 */
        queryData: function (flag) {
            var $this = this;
            $headerObj.searchObj.params.queryMin = $containerObj.queryMin;
            $headerObj.searchObj.params.queryMax = $containerObj.queryMax;
            if (flag) { // flag：点击气泡时，传true，只查询除气泡图以外的数据
                $containerObj.queryData('hospital');
                $containerObj.queryData('brand');
                $containerObj.queryData('assets');
            } else {
                $containerObj.queryData('hospital');
                $containerObj.queryData('model');
                $containerObj.queryData('brand');
                $containerObj.queryData('assets');
                // 触发 月份显示、全部数据 下拉框，使页面显示全部数据
                $containerObj.chartObj.changeSelect.val(0).trigger('change');
                publicAjax(basePath + 'charts/area/cost/overview-hospital', 'post', $headerObj.searchObj.params, function (data) {
                    $this.data = data.data;
                    $this.setData();  // 设置数据
                }, true);
            }
        },
        /* 设置概览框数据 */
        setData: function () {
            var $this = this;
            // 设置标题收支比范围
            publicAjax(basePath + 'charts/area/cost/interval', 'post', $headerObj.searchObj.params, function (data) {
                var totalTitle = $this.main.find('.total-title');
                totalTitle.eq(1).html($.i18n.prop('performance.overview.szb') + '≥' + data.data.queryMax);
                totalTitle.eq(2).html($.i18n.prop('performance.overview.szb') + '' + data.data.queryMin + '-' + data.data.queryMax);
                totalTitle.eq(3).html($.i18n.prop('performance.overview.szb') + '<' + data.data.queryMin);
                totalTitle.eq(0).data().queryMin = null;
                totalTitle.eq(0).data().queryMax = null;
                totalTitle.eq(1).data().queryMin = data.data.queryMax;
                totalTitle.eq(1).data().queryMax = null;
                totalTitle.eq(2).data().queryMin = data.data.queryMin;
                totalTitle.eq(2).data().queryMax = data.data.queryMax;
                totalTitle.eq(3).data().queryMin = null;
                totalTitle.eq(3).data().queryMax = data.data.queryMin;

                totalTitle.off().on('click', function () {
                    $headerObj.searchObj.params.queryMin = $containerObj.queryMin = $(this).data().queryMin;
                    $headerObj.searchObj.params.queryMax = $containerObj.queryMax = $(this).data().queryMax;
                    totalTitle.removeClass('active');
                    $(this).addClass('active');
                    $containerObj.chartObj.changeSelect.val(0).trigger('change');
                    loading(function () {
                        $containerObj.queryData('hospital');
                        $containerObj.queryData('type');
                        $containerObj.queryData('assets');
                    });
                });
            }, true);

            var list = this.data.list;
            $this.main.find('#total-value-1-1').html(fix2(list.overview_1.jnTotalIncome / PRICE_CONVERT)); // 总收入
            $this.main.find('#total-value-1-2').html(fix2(list.overview_1.jnwyIncomePercentage)); // 万元收入
            $this.main.find('#total-value-1-3').html(fix2(list.overview_1.jnszPercentage)); // 收支比
            $this.main.find('#total-value-1-4').html(fix0(list.overview_1.hospitalNum)); // 医院数量
            $this.main.find('#total-value-1-5').html(fix2(list.overview_1.jnTotalExpenditure / PRICE_CONVERT)); // 总支出
            $this.main.find('#total-value-1-6').html(fix2(list.overview_1.jnwyExpenditurePercentage)); // 万元支出

            $this.main.find('#total-value-2-1').html(fix2(list.overview_2.jnTotalIncome / PRICE_CONVERT)); // 总收入
            $this.main.find('#total-value-2-2').html(fix2(list.overview_2.jnwyIncomePercentage)); // 万元收入
            $this.main.find('#total-value-2-3').html(fix2(list.overview_2.jnszPercentage)); // 收支比
            $this.main.find('#total-value-2-4').html(fix0(list.overview_2.hospitalNum)); // 医院数量
            $this.main.find('#total-value-2-5').html(fix2(list.overview_2.jnTotalExpenditure / PRICE_CONVERT)); // 总支出
            $this.main.find('#total-value-2-6').html(fix2(list.overview_2.jnwyExpenditurePercentage)); // 万元支出

            $this.main.find('#total-value-3-1').html(fix2(list.overview_3.jnTotalIncome / PRICE_CONVERT)); // 总收入
            $this.main.find('#total-value-3-2').html(fix2(list.overview_3.jnwyIncomePercentage)); // 万元收入
            $this.main.find('#total-value-3-3').html(fix2(list.overview_3.jnszPercentage)); // 收支比
            $this.main.find('#total-value-3-4').html(fix0(list.overview_3.hospitalNum)); // 医院数量
            $this.main.find('#total-value-3-5').html(fix2(list.overview_3.jnTotalExpenditure / PRICE_CONVERT)); // 总支出
            $this.main.find('#total-value-3-6').html(fix2(list.overview_3.jnwyExpenditurePercentage)); // 万元支出

            $this.main.find('#total-value-4-1').html(fix2(list.overview_4.jnTotalIncome / PRICE_CONVERT)); // 总收入
            $this.main.find('#total-value-4-2').html(fix2(list.overview_4.jnwyIncomePercentage)); // 万元收入
            $this.main.find('#total-value-4-3').html(fix2(list.overview_4.jnszPercentage)); // 收支比
            $this.main.find('#total-value-4-4').html(fix0(list.overview_4.hospitalNum)); // 医院数量
            $this.main.find('#total-value-4-5').html(fix2(list.overview_4.jnTotalExpenditure / PRICE_CONVERT)); // 总支出
            $this.main.find('#total-value-4-6').html(fix2(list.overview_4.jnwyExpenditurePercentage)); // 万元支出
        }
    };
    /* echart对象 */
    $containerObj.chartObj = {
        main: $containerObj.main.find('.main-chart'), // echarts图表模块主元素
        changeSelect: $('#chart-change'), // 月份显示/全部数据 下拉框
        data: { // echarts图表数据
            seriesData: [],
            sizeMin: 0,
            sizeMax: 0,
            sizeRange: 0
        },
        yearData: { // 月份显示
            seriesData: [],
            xAxis: []
        },
        init: function () {
            this.initChart(); // 初始化echats图表
            this.bindEvent(); // 绑定事件
        },
        /* 初始化echarts图表 */
        initChart: function () {
            this.chart = echarts.init(this.main.find('#chart')[0]);
            this.chart.on('click', this.click.bind(this));  // echarts绑定click事件
        },
        /* echarts图表click事件，点击气泡，top5高亮，筛选其他数据 */
        click: function (params) {
            if ((params.componentType !== 'markLine') && (this.changeSelect.val() !== '1')) { // 点击的不是平均线及月份显示不显示
                loading();
                setTimeout(function () {
                    var index = -1, // 点击气泡图的index
                        id = params.data[6],
                        length = $containerObj.data.model.list.length; // 医院列表的长度
                    /* 点击的气泡已经筛选了，就取消高亮，没筛选就加上高亮 */
                    if ($headerObj.searchObj.params.modelName === id) {
                        $headerObj.searchObj.params.modelName = null;
                        $containerObj.totalObj.queryData(true);
                        index = -1;
                    } else {
                        $headerObj.searchObj.params.modelName = id;
                        $containerObj.totalObj.queryData(true);
                        index = $containerObj.data.model.list.getIndexByKey('id', id);
                    }
                    /* 设置top5数据 */
                    if (length > 5) {
                        if (index > length - 3) {
                            $containerObj.top5Obj.convertData('model', length - 5, length, index);
                        }
                        if (index < 2) {
                            $containerObj.top5Obj.convertData('model', 0, length > 5 ? 5 : length, index);
                        } else {
                            $containerObj.top5Obj.convertData('model', index - 2, index + 3, index);
                        }
                    } else {
                        $containerObj.top5Obj.convertData('model', 0, length, index);
                    }
                }, 10);
            }
        },
        /* 转换echarts数据 */
        convertData: function () {
            var data = $containerObj.data.model;
            this.data.seriesData = [];
            for (var i = 0; i < data.list.length; i++) {
                this.data.seriesData.push([
                    fixLine(data.list[i].jnAssetsAmount / PRICE_CONVERT),
                    fixLine(data.list[i].jnszPercentage),
                    30,
                    fixStr(data.list[i].name),
                    fixLine(data.list[i].jnIncome / PRICE_CONVERT),
                    fixLine(data.list[i].jnExpenditure / PRICE_CONVERT),
                    data.list[i].id
                ]);
            }
            this.data.avgSzPercentage = fix0(data.avgSzPercentage);
            this.data.avgAssetsAmount = fix2(data.avgAssetsAmount / PRICE_CONVERT);
        },
        /* 设置echarts图表 */
        setChart: function () {
            this.optionChart.series[0].data = this.data.seriesData;
            this.optionChart.series[0].markLine.data[0].xAxis = this.data.avgAssetsAmount;
            this.optionChart.series[0].markLine.data[1].yAxis = this.data.avgSzPercentage;

            this.chart.clear();
            this.chart.setOption(this.optionChart);
        },
        /* 查询月份显示 */
        queryYearData: function () {
            var $this = this;
            publicAjax(basePath + 'charts/area/cost/month-trend', 'post', $headerObj.searchObj.params, function (data) {
                $containerObj.data.year = {list: data.data.calTotal()};
                $this.convertYearData();
                $this.setYearChart();
                $containerObj.top5Obj.convertData('year', 0, data.data.length);
                // 设置模态框数据
                $containerObj.modalObj.data.year = $.extend(true, {}, $containerObj.data.year);
                loading(true);
            }, true);
        },
        /* 转换月份显示 */
        convertYearData: function () {
            var data = $containerObj.data.year;
            this.yearData.xAxis = [];
            this.yearData.seriesData = [[], []];
            for (var i = 0; i < data.list.length; i++) {
                this.yearData.xAxis.push(data.list[i].monthName);
                this.yearData.seriesData[0].push(data.list[i].jnszPercentage);
                this.yearData.seriesData[1].push(data.list[i].tbszPercentage);
            }
        },
        /* 设置月份显示echarts图表 */
        setYearChart: function () {
            this.optionYear.xAxis.data = this.yearData.xAxis;
            this.optionYear.series[0].data = this.yearData.seriesData[0];
            this.optionYear.series[1].data = this.yearData.seriesData[1];

            this.chart.clear();
            this.chart.setOption(this.optionYear);
        },
        /* 绑定事件 */
        bindEvent: function () {
            var $this = this;
            var yearBtn = this.main.find('.year-btn'),
                chartTitle = this.main.find('.chart-title');
            yearBtn.on('click', function () {
                var value = 1 - parseInt($this.changeSelect.val());
                $this.changeSelect.val(value).trigger('change');
            });
            /* 月份显示/全部显示 下拉框change事件 */
            this.changeSelect.on('change', function () {
                var value = parseInt($(this).val());
                if (value) {
                    loading();
                    yearBtn.addClass('active').find('span').html($.i18n.prop('charts.button.qbxs'));
                    chartTitle.html($.i18n.prop('charts.button.yfxs')).data().tag = 'year';
                    $this.main.find('.quadrantContainner').hide();
                    $containerObj.top5Obj.changeShow(value);
                    $this.queryYearData();
                } else {
                    yearBtn.removeClass('active').find('span').html($.i18n.prop('charts.button.yfxs'));
                    chartTitle.html($.i18n.prop('charts.title.yljgfb')).data().tag = 'hospital';
                    $this.main.find('.quadrantContainner').show();
                    $containerObj.top5Obj.changeShow(value);
                    $this.chart.clear();
                    $this.chart.setOption($this.optionChart);
                }
            });

            /* 处理象限点击 */
            var currentOptionTemp,
                optionAgelimit = this.optionChart;
            this.main.find('.quadrant').on('click', function () {
                var index = $(this).index();
                var arr = optionAgelimit.series[0].data;
                var markLimeArr = optionAgelimit.series[0].markLine.data;
                var arrTemp = [];
                currentOptionTemp = optionAgelimit;
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active');
                    arrTemp = arr;
                    currentOptionTemp.series[0].markLine.data = markLimeArr;
                } else if (index === 1) {
                    $(this).addClass('active').siblings().removeClass('active');
                    for (var i = 0; i < arr.length; i++) {
                        if ((parseFloat(arr[i][0]) >= parseFloat(markLimeArr[0].xAxis)) && (parseFloat(arr[i][1]) >= parseFloat(markLimeArr[1].yAxis))) {
                            arrTemp.push(arr[i]);
                        } else {
                            arrTemp.push([0, 0, 0, i])
                        }
                    }
                    currentOptionTemp.series[0].markLine.data = [];
                } else if (index === 2) {
                    $(this).addClass('active').siblings().removeClass('active');
                    for (var i = 0; i < arr.length; i++) {
                        if ((parseFloat(arr[i][0]) < parseFloat(markLimeArr[0].xAxis)) && (parseFloat(arr[i][1]) >= parseFloat(markLimeArr[1].yAxis))) {
                            arrTemp.push(arr[i]);
                        } else {
                            arrTemp.push([0, 0, 0, i])
                        }
                    }
                    currentOptionTemp.series[0].markLine.data = [];
                } else if (index === 3) {
                    $(this).addClass('active').siblings().removeClass('active');
                    for (var i = 0; i < arr.length; i++) {
                        if ((parseFloat(arr[i][0]) < parseFloat(markLimeArr[0].xAxis)) && (parseFloat(arr[i][1]) < parseFloat(markLimeArr[1].yAxis))) {
                            arrTemp.push(arr[i]);
                        } else {
                            arrTemp.push([0, 0, 0, i])
                        }
                    }
                    currentOptionTemp.series[0].markLine.data = [];
                } else if (index === 4) {
                    $(this).addClass('active').siblings().removeClass('active');
                    for (var i = 0; i < arr.length; i++) {
                        if ((parseFloat(arr[i][0]) >= parseFloat(markLimeArr[0].xAxis)) && (parseFloat(arr[i][1]) < parseFloat(markLimeArr[1].yAxis))) {
                            arrTemp.push(arr[i]);
                        } else {
                            arrTemp.push([0, 0, 0, i])
                        }
                    }
                    currentOptionTemp.series[0].markLine.data = [];
                }
                currentOptionTemp.series[0].data = arrTemp;
                $this.chart.clear();
                $this.chart.setOption(currentOptionTemp);
                optionAgelimit.series[0].data = arr;
                optionAgelimit.series[0].markLine.data = markLimeArr;
            });
        },
        optionChart: {
            color: ['#31860f'],
            backgroundColor: '#373945',
            tooltip: {
                trigger: 'item',
                textStyle: {
                    fontSize: 0.28 * rem
                },
                formatter: function (a) {
                    if (a.componentType === 'markLine') {
                        return a.name + ':' + a.value;
                    } else {
                        return a.data[3] + '<br/>'
                            + $.i18n.prop('charts.select.sr') + '：' + fix2(a.data[4]) + $.i18n.prop('share.unit.wanyuan') + '<br/>'
                            + $.i18n.prop('charts.select.zc') + '：' + fix2(a.data[5]) + $.i18n.prop('share.unit.wanyuan') + '<br/>'
                            + $.i18n.prop('charts.select.szb') + '：' + fix2(a.data[1]);
                    }
                }
            },
            dataZoom: [{
                type: 'inside',
                xAxisIndex: [0],
                start: 0,
                end: 100
            },
                {
                    type: 'inside',
                    yAxisIndex: [0],
                    start: 0,
                    end: 100
                }
            ],
            grid: {
                top: 1.6 * rem,
                left: rem * 0.4,
                right: 2.4 * rem,
                bottom: 0,
                containLabel: true
            },
            xAxis: {
                name: $.i18n.prop('charts.axis.sbje-wy'),
                type: 'value',
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: parseInt(0.28 * rem),
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#f00',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            },
            yAxis: [{
                name: $.i18n.prop('performance.table.szb'),
                type: 'value',
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: 0.28 * rem,
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#f00',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }],
            series: [{
                type: 'scatter',
                data: [],
                symbolSize: function (data) {
                    if (data[2] === 0) return 0;
                    if ($containerObj.chartObj.data.sizeRange == 0) return 35;
                    return data[2] === 0 ? 0 : (30 * (data[2] - $containerObj.chartObj.data.sizeMin) / $containerObj.chartObj.data.sizeRange + 20);
                },
                markLine: {
                    lineStyle: {
                        normal: {
                            color: MARKLINE_COLOR,
                            type: 'dashed',
                            opacity: 0.4
                        }
                    },
                    data: [
                        {type: 'average', name: $.i18n.prop('charts.avg.sbjepjz(wy)'), valueIndex: 0, xAxis: null},
                        {type: 'average', name: $.i18n.prop('charts.axis.szbpjz(%)'), valueIndex: 1, yAxis: null}
                    ]
                }
            }]
        },
        optionYear: {
            color: ['#2089ff', '#6c63ff', '#12a0df', '#fb8a22', '#fef534'],
            backgroundColor: '#373945',
            tooltip: {
                trigger: 'axis',
                axisPointer: { // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                },
                textStyle: {
                    fontSize: 0.28 * rem
                },
                formatter: function (params) {
                    return params[0].name + '：<br>' +
                        $.i18n.prop('charts.select.szb') + '：' + fix2(params[0].value) + '<br>' +
                        $.i18n.prop('performance.legend.szbtb') + '：' + fix2(params[1].value) + '%';
                }
            },
            legend: {
                x: "right",
                top: 0.4 * rem,
                textStyle: {
                    color: '#AAA',
                    fontSize: 0.28 * rem
                },
                data: [$.i18n.prop('charts.select.szb'), $.i18n.prop('performance.legend.szbtb')]
            },
            grid: {
                top: 1.6 * rem,
                left: rem * 0.4,
                right: rem,
                bottom: 0,
                containLabel: true
            },
            xAxis: {
                type: 'category',
                data: [],
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: parseInt(0.28 * rem),
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#f00',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            },
            yAxis: [{
                name: $.i18n.prop('charts.select.szb'),
                type: 'value',
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: parseInt(0.28 * rem),
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#fff',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }, {
                name: $.i18n.prop('performance.legend.szbtb') + '：%',
                type: 'value',
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: parseInt(0.28 * rem),
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#fff',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }],
            series: [{
                name: $.i18n.prop('charts.select.szb'),
                type: 'line',
                barGap: '0%',
                barMaxWidth: 0.8 * rem,
                data: []
            }, {
                name: $.i18n.prop('performance.legend.szbtb'),
                type: 'line',
                yAxisIndex: 1,
                barMaxWidth: 0.8 * rem,
                data: []
            }]
        }
    };
    /* Top5对象 */
    $containerObj.top5Obj = {
        main: $containerObj.main.find('.main-top5'), // top5主对象
        data: {}, // top5数据存储 hospital、type、assets、year
        status: {
            array: {},
            getStatus: function () {
                var arr = $headerObj.page[$headerObj.page.current].query;
                for (var i = 0; i < arr.length; i++) {
                    if (!this.array[arr[i]]) return false;
                }
                return true;
            },
            resetStatus: function () {
                for (var key in this.array) {
                    this.array[key] = false;
                }
            }
        },
        /* top5对象初始化方法 */
        init: function () {

        },
        /* 切换显示 月份显示（传值） or 全部显示 */
        changeShow: function (value) {
            if (value) {
                this.main.find('.top5').hide();
                this.main.find('.top5-year, .top5-assets').show();
            } else {
                this.main.find('.top5-year').hide().siblings('.top5').show();
            }
        },
        /* 转化top5数据 */
        convertData: function (tag, start, end, index) {
            this.status.array[tag] = true;
            var data = $containerObj.data;
            this.data[tag] = [];
            if (tag === 'type') {
                var data2 = data[tag].list[-1].list ? data[tag].list[-1] : {list: []};
                (data2.list || []).sortByKey('jnAssetsAmount');
                for (var i = start; i < end; i++) {
                    this.data[tag].push([
                        data2.list[i].name,
                        data2.list[i].id,
                        data2.list[i].jnAssetsAmount / PRICE_CONVERT,
                        data2.list[i].jnszPercentage,
                        i === index
                    ]);
                }
            } else {
                for (var i = start; i < end; i++) {
                    this.data[tag].push([
                        data[tag].list[i][tag === 'year' ? 'monthName' : 'name'],
                        data[tag].list[i].id,
                        data[tag].list[i][tag === 'assets' ? 'amount' : 'jnAssetsAmount'] / PRICE_CONVERT,
                        data[tag].list[i].jnszPercentage,
                        i === index
                    ]);
                }
            }
            this.setData(tag, start + 1);
            if (this.status.getStatus()) {
                loading(true);
                this.status.resetStatus();
            }
        },
        /* 设置top5数据 */
        setData: function (tag, start) {
            var str = '',
                active = '';
            for (var i = 0; i < this.data[tag].length; i++) {
                active = this.data[tag][i][4] ? ' class="active"' : '';
                str += (
                    '<li><a' + active + '>' +
                    '<span onclick="$containerObj.query(\'' + tag + '\',\'' + this.data[tag][i][1] + '\')" ' +
                    'title="' + (start + i) + ' ' + fixStr(this.data[tag][i][0]) + '" class="top5-key underline">' + fixStr(this.data[tag][i][0]) + '</span>' +
                    (tag === 'year'
                        ? '<span class="top5-value1"></span><span class="top5-value2">' + fix2(this.data[tag][i][3]) + '</span>'
                        : '<span data-value="' + fix2(this.data[tag][i][3]) + '" class="top5-value1 jqmeter">' + fix2(this.data[tag][i][3]) + '</span>' +
                        '<span class="top5-value2">' + fix2(this.data[tag][i][2]) + '</span>') +
                    '</a></li>'
                );
            }
            this.main.find('.top5-' + tag + ' ul').html(str);
            // this.initJQMeter(tag);
        },
        /* 初始化进度条 */
        initJQMeter: function (tag) {
            if (tag === 'assets') {
                this.main.find('.top5-' + tag + ' .jqmeter').each(function () {
                    $(this).jQMeter({
                        goal: '$1,00',
                        raised: '$' + parseInt($(this).text()),
                        width: '90%',
                        height: '0.24rem'
                    });
                });
            }
        }
    };
    /* 模态框对象 */
    $containerObj.modalObj = {
        main: $('#detail-modal'), // 模态框主对象
        assetsMain: $('#assets-modal'), // 设备、新增、报废设备详情， 覆盖 header
        yearMain: $('#year-modal'), // 月份显示模态框
        data: {}, // 模态框数据
        /* 初始化模态框对象 */
        init: function () {
            this.initModal(); // 初始化模态框
            this.bindEvent(); // 绑定事件
        },
        /* 初始化模态框 */
        initModal: function () {
            var $this = this;
            /* 月份显示模态框 */
            this.yearMain.iziModal({
                title: 'title',
                headerColor: '#222431',
                width: '100%',
                radius: 3,
                zindex: 70,
                history: false,
                bodyOverflow: true,
                fullscreen: true,
                overlayColor: 'rgba(0, 0, 0, 0)',
                onOpening: function () {
                    /* 添加导出按钮 */
                    if (!$this.yearMain.find('.iziModal-header').find('.export_excel').length) {
                        $this.yearMain.find('.iziModal-header').append('<a class="iziModal-button export_excel"' +
                            ' href="javascript:void(0);" onclick="exportExcel(\'#year-modal\')" title="' + $.i18n.prop('share.sift.dc') + '"><i class="fa' +
                            ' fa-upload"></i></a>');
                    }
                },
                onOpened: function () {
                    /* 设置模态框高度 */
                    var height = $this.yearMain.height() - $this.yearMain.find('.iziModal-header').outerHeight();
                    $this.yearMain.find('.iziModal-content').height(height);
                }
            });
            /* 主模态框 */
            this.main.iziModal({
                title: 'title',
                headerColor: '#222431',
                width: '100%',
                radius: 3,
                zindex: 80,
                history: false,
                bodyOverflow: true,
                fullscreen: true,
                overlayColor: 'rgba(0, 0, 0, 0)',
                onOpening: function () {
                    /* 添加导出按钮 */
                    if (!$this.main.find('.iziModal-header').find('.export_excel').length) {
                        $this.main.find('.iziModal-header').append('<a class="iziModal-button export_excel" href="javascript:void(0);" onclick="exportExcel(\'#detail-modal\')" title="' + $.i18n.prop('share.sift.dc') + '"><i class="fa fa-upload"></i></a>');
                    }
                },
                onOpened: function () {
                    /* 设置模态框高度 */
                    var height = $this.main.height() - $this.main.find('.iziModal-header').outerHeight();
                    $this.main.find('.iziModal-content').height(height);
                }
            });
            /* 设备、新增、报废模态框 */
            this.assetsMain.iziModal({
                title: $.i18n.prop('share.talbe.sbxq'),
                headerColor: '#222431',
                width: '100%',
                radius: 3,
                zindex: 111,
                history: false,
                bodyOverflow: true,
                fullscreen: true,
                overlayColor: 'rgba(0, 0, 0, 0)',
                onOpening: function () {
                    /* 添加导出按钮 */
                    if (!$this.assetsMain.find('.iziModal-header').find('.export_excel').length) {
                        $this.assetsMain.find('.iziModal-header').append('<a class="iziModal-button export_excel" href="javascript:void(0);" onclick="exportExcel(\'#assets-modal\')" title="' + $.i18n.prop('share.sift.dc') + '"><i class="fa fa-upload"></i></a>');
                    }
                },
                onOpened: function () {
                    /* 设置模态框高度 */
                    var height = $this.assetsMain.height() - $this.assetsMain.find('.iziModal-header').outerHeight();
                    $this.assetsMain.find('.iziModal-content').height(height);
                }
            });
            // 月份显示表格对象
            this.yearTable = this.yearMain.find('#year-table');
            this.yearThead = this.yearTable.find('thead');
            this.yearTbody = this.yearTable.find('tbody');
            this.yearTfoot = this.yearTable.find('tfoot');
            // 主表格对象
            this.table = this.main.find('#detail-table');
            this.thead = this.table.find('thead');
            this.tbody = this.table.find('tbody');
            this.tfoot = this.table.find('tfoot');
            // 设备表格对象
            this.assetsTable = this.assetsMain.find('#assets-table');
            this.assetsThead = this.assetsTable.find('thead');
            this.assetsTbody = this.assetsTable.find('tbody');
            this.assetsTfoot = this.assetsTable.find('tfoot');
        },
        /* 设置模态框数据 */
        setModal: function (tag, key, sorting, param) {
            var $this = this;
            loading(function () {
                var theadStr = '',
                    tbodyStr = '',
                    tfootStr = '',
                    list = ($this.data[tag].list || []).sortByKey(sorting, key);  // 数据列表根据key排序，sorting郑旭或倒序
                // 清空表格内容
                $this.thead.html('');
                $this.tbody.html('');
                $this.tfoot.html('');
                $this.main.data().tag = tag; // 设置tag，用于模态框显示时，筛选刷新模态框数据
                if (tag === 'hospital') {
                    $this.main.iziModal('setTitle', $.i18n.prop('share.table.title.yljgfbxq'));
                    theadStr = (
                        '<tr><th class="tc">#</th>' +
                        '<th class="sort tl" data-key="name">'+$.i18n.prop('index.table.yymc')+'</th>' +
                        '<th class="sort tr" data-key="jnAssetsAmount">'+$.i18n.prop('index.table.sbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnIncome">'+$.i18n.prop('performance.table.sr(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnIncomeAssetsNum">'+$.i18n.prop('performance.table.srsbs(t)')+'</th>' +
                        '<th class="sort tr" data-key="jnExpenditure">'+$.i18n.prop('performance.table.zc(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnExpenditureAssetsNum">'+$.i18n.prop('performance.table.zcsbs(t)')+'</th>' +
                        '<th class="sort tr" data-key="jnszPercentage">'+$.i18n.prop('performance.table.szb')+'</th>' +
                        '<th class="sort tr" data-key="tbszPercentage">'+$.i18n.prop('performance.table.szbtb(%)')+'</th>' +
                        '<th class="sort tr" data-key="jnwyPercentage">'+$.i18n.prop('performance.table.wysr')+'</th>' +
                        '<th class="sort tr" data-key="jnwyExpenditurePercentage">'+$.i18n.prop('performance.table.wyzc')+'</th>' +
                        '</tr>'
                    );
                    tfootStr = (
                        '<tr>' +
                        '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                        '<td class="tl">' + list.length + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnAssetsAmount / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnIncome / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].jnIncomeAssetsNum) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnExpenditure / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].jnExpenditureAssetsNum) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnszPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].tbszPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnwyPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnwyExpenditurePercentage / list.length) + '</td>' +
                        '</tr>'
                    );
                    for (var i = 0; i < list.length; i++) {
                        tbodyStr += (
                            '<tr>' +
                            '<td class="tc">' + (i + 1) + '</td>' +
                            '<td class="spanTitle" onclick="$containerObj.query(\'' + tag + '\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnAssetsAmount / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnIncome / PRICE_CONVERT) + '</td>' +
                            '<td class="tr' + (list[i].jnIncomeAssetsNum ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'income\',\'{hospitalId:[' + list[i].id + ']}\',\'' + list[i].jnIncomeAssetsNum + '\')">' +
                            fix0(list[i].jnIncomeAssetsNum) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnExpenditure / PRICE_CONVERT) + '</td>' +
                            '<td class="tr' + (list[i].jnExpenditureAssetsNum ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'expenditure\',\'{hospitalId:[' + list[i].id + ']}\',\'' + list[i].jnExpenditureAssetsNum + '\')">' +
                            fix0(list[i].jnExpenditureAssetsNum) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnszPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].tbszPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnwyPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnwyExpenditurePercentage) + '</td>' +
                            '</tr>'
                        );
                    }
                } else if (tag === 'model') {
                    $this.main.iziModal('setTitle', $.i18n.prop('share.table.title.sbxhfbxq'));
                    theadStr = (
                        '<tr><th class="tc">#</th>' +
                        '<th class="sort tl" data-key="name">'+$.i18n.prop('share.table.head.sbxh')+'</th>' +
                        '<th class="sort tr" data-key="jnAssetsAmount">'+$.i18n.prop('index.table.sbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnIncome">'+$.i18n.prop('performance.table.sr(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnIncomeAssetsNum">'+$.i18n.prop('performance.table.srsbs(t)')+'</th>' +
                        '<th class="sort tr" data-key="jnExpenditure">'+$.i18n.prop('performance.table.zc(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnExpenditureAssetsNum">'+$.i18n.prop('performance.table.zcsbs(t)')+'</th>' +
                        '<th class="sort tr" data-key="jnszPercentage">'+$.i18n.prop('performance.table.szb')+'</th>' +
                        '<th class="sort tr" data-key="tbszPercentage">'+$.i18n.prop('performance.table.szbtb(%)')+'</th>' +
                        '<th class="sort tr" data-key="jnwyPercentage">'+$.i18n.prop('performance.table.wysr')+'</th>' +
                        '<th class="sort tr" data-key="jnwyExpenditurePercentage">'+$.i18n.prop('performance.table.wyzc')+'</th>' +
                        '</tr>'
                    );
                    tfootStr = (
                        '<tr>' +
                        '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                        '<td class="tl">' + list.length + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnAssetsAmount / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnIncome / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].jnIncomeAssetsNum) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnExpenditure / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].jnExpenditureAssetsNum) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnszPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].tbszPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnwyPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnwyExpenditurePercentage / list.length) + '</td>' +
                        '</tr>'
                    );
                    for (var i = 0; i < list.length; i++) {
                        tbodyStr += (
                            '<tr>' +
                            '<td class="tc">' + (i + 1) + '</td>' +
                            '<td class="spanTitle" onclick="$containerObj.query(\'model\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnAssetsAmount / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnIncome / PRICE_CONVERT) + '</td>' +
                            '<td class="tr' + (list[i].jnIncomeAssetsNum ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'income\',\'{modelName:' + list[i].id + (param || '') + '}\',\'' + list[i].jnIncomeAssetsNum + '\')">' +
                            fix0(list[i].jnIncomeAssetsNum) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnExpenditure / PRICE_CONVERT) + '</td>' +
                            '<td class="tr' + (list[i].jnExpenditureAssetsNum ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'expenditure\',\'{modelName:' + list[i].id + (param || '') + '}\',\'' + list[i].jnExpenditureAssetsNum + '\')">' +
                            fix0(list[i].jnExpenditureAssetsNum) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnszPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].tbszPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnwyPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnwyExpenditurePercentage) + '</td>' +
                            '</tr>'
                        );
                    }
                } else if (tag === 'brand') {
                    $this.main.iziModal('setTitle', $.i18n.prop('share.table.title.sbcjfbxq'));
                    theadStr = (
                        '<tr><th class="tc">#</th>' +
                        '<th class="sort tl" data-key="name">'+$.i18n.prop('share.table.head.sbcj')+'</th>' +
                        '<th class="sort tr" data-key="jnAssetsAmount">'+$.i18n.prop('index.table.sbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnIncome">'+$.i18n.prop('performance.table.sr(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnIncomeAssetsNum">'+$.i18n.prop('performance.table.srsbs(t)')+'</th>' +
                        '<th class="sort tr" data-key="jnExpenditure">'+$.i18n.prop('performance.table.zc(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnExpenditureAssetsNum">'+$.i18n.prop('performance.table.zcsbs(t)')+'</th>' +
                        '<th class="sort tr" data-key="jnszPercentage">'+$.i18n.prop('performance.table.szb')+'</th>' +
                        '<th class="sort tr" data-key="tbszPercentage">'+$.i18n.prop('performance.table.szbtb(%)')+'</th>' +
                        '<th class="sort tr" data-key="jnwyPercentage">'+$.i18n.prop('performance.table.wysr')+'</th>' +
                        '<th class="sort tr" data-key="jnwyExpenditurePercentage">'+$.i18n.prop('performance.table.wyzc')+'</th>' +
                        '</tr>'
                    );
                    tfootStr = (
                        '<tr>' +
                        '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                        '<td class="tl">' + list.length + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnAssetsAmount / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnIncome / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].jnIncomeAssetsNum) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnExpenditure / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].jnExpenditureAssetsNum) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnszPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].tbszPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnwyPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnwyExpenditurePercentage / list.length) + '</td>' +
                        '</tr>'
                    );
                    for (var i = 0; i < list.length; i++) {
                        tbodyStr += (
                            '<tr>' +
                            '<td class="tc">' + (i + 1) + '</td>' +
                            '<td class="spanTitle" onclick="$containerObj.query(\'' + tag + '\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnAssetsAmount / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnIncome / PRICE_CONVERT) + '</td>' +
                            '<td class="tr' + (list[i].jnIncomeAssetsNum ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'income\',\'{brandId:[' + list[i].id + ']}\',\'' + list[i].jnIncomeAssetsNum + '\')">' +
                            fix0(list[i].jnIncomeAssetsNum) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnExpenditure / PRICE_CONVERT) + '</td>' +
                            '<td class="tr' + (list[i].jnExpenditureAssetsNum ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'expenditure\',\'{brandId:[' + list[i].id + ']}\',\'' + list[i].jnExpenditureAssetsNum + '\')">' +
                            fix0(list[i].jnExpenditureAssetsNum) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnszPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].tbszPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnwyPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnwyExpenditurePercentage) + '</td>' +
                            '</tr>'
                        );
                    }
                } else if (tag === 'assets') {
                    $this.main.iziModal('setTitle', $.i18n.prop('share.table.title.sbfbxq'));
                    theadStr = (
                        '<tr><th class="tc">#</th>' +
                        '<th class="sort tl" data-key="name">'+$.i18n.prop('share.assets.sbmc')+'</th>' +
                        '<th class="sort tl" data-key="firstTypeName">'+$.i18n.prop('share.table.head.sblx')+'</th>' +
                        '<th class="sort tl" data-key="hospital">'+$.i18n.prop('share.assets.ssyy')+'</th>' +
                        '<th class="sort tl" data-key="department">'+$.i18n.prop('share.assets.ssks')+'</th>' +
                        '<th class="sort tl" data-key="manufacturer">'+$.i18n.prop('share.table.head.sbcj')+'</th>' +
                        '<th class="sort tl" data-key="sn">'+$.i18n.prop('share.assets.snbh')+'</th>' +
                        '<th class="sort tl" data-key="assetsNo">'+$.i18n.prop('share.assets.zcbh')+'</th>' +
                        '<th class="sort tr" data-key="amount">'+$.i18n.prop('share.assets.sbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="jnIncome">'+$.i18n.prop('performance.assets.jnsr(wy)')+'</th>' +
                        '<th class="sort tr" data-key="qnIncome">'+$.i18n.prop('performance.assets.qnsr(wy)')+'</th>' +
                        '<th class="sort tr" data-key="tbsrPercentage">'+$.i18n.prop('performance.assets.srtb(%)')+'</th>' +
                        '<th class="sort tr" data-key="jnExpenditure">'+$.i18n.prop('performance.assets.jnzc(wy)')+'</th>' +
                        '<th class="sort tr" data-key="qnExpenditure">'+$.i18n.prop('performance.assets.qnzc(wy)')+'</th>' +
                        '<th class="sort tr" data-key="tbzcPercentage">'+$.i18n.prop('performance.assets.zctb(%)')+'</th>' +
                        '<th class="sort tr" data-key="jnszPercentage">'+$.i18n.prop('performance.assets.jnszb(%)')+'</th>' +
                        '<th class="sort tr" data-key="qnszPercentage">'+$.i18n.prop('performance.assets.qnszb(%)')+'</th>' +
                        '</tr>'
                    );
                    tfootStr = (
                        '<tr>' +
                        '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                        '<td class="tl">' + list.length + '</td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tr">' + fix2(list[-1].amount / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnIncome / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].qnIncome / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].tbsrPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnExpenditure / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].qnExpenditure / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].tbzcPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnszPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].qnszPercentage / list.length) + '</td>' +
                        '</tr>'
                    );
                    for (var i = 0; i < list.length; i++) {
                        tbodyStr += (
                            '<tr>' +
                            '<td class="tc">' + (i + 1) + '</td>' +
                            '<td class="spanTitle" onclick="$containerObj.query(\'' + tag + '\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].firstTypeName) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].hospitalName) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].departmentName) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].manufacturer) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].sn) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].assetsNo) + '</td>' +
                            '<td class="tr">' + fix2(list[i].amount / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnIncome / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].qnIncome / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].tbsrPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnExpenditure / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].qnExpenditure / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].tbzcPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnszPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].qnszPercentage) + '</td>' +
                            '</tr>'
                        );
                    }
                } else if (tag === 'year') {
                    $this.yearMain.iziModal('setTitle', $.i18n.prop('charts.button.yfxs'));
                    theadStr = (
                        '<tr><th class="tc">#</th>' +
                        '<th class="sort tl" data-key="month">'+$.i18n.prop('share.table.head.yf')+'</th>' +
                        '<th class="sort tr" data-key="jnIncome">'+$.i18n.prop('performance.assets.jnsr(wy)')+'</th>' +
                        '<th class="sort tr" data-key="qnIncome">'+$.i18n.prop('performance.assets.qnsr(wy)')+'</th>' +
                        '<th class="sort tr" data-key="tbsrPercentage">'+$.i18n.prop('performance.assets.srtb(%)')+'</th>' +
                        '<th class="sort tr" data-key="jnExpenditure">'+$.i18n.prop('performance.assets.jnzc(wy)')+'</th>' +
                        '<th class="sort tr" data-key="qnExpenditure">'+$.i18n.prop('performance.assets.qnzc(wy)')+'</th>' +
                        '<th class="sort tr" data-key="tbzcPercentage">'+$.i18n.prop('performance.assets.zctb(%)')+'</th>' +
                        '<th class="sort tr" data-key="jnszPercentage">'+$.i18n.prop('performance.assets.jnszb(%)')+'</th>' +
                        '<th class="sort tr" data-key="qnszPercentage">'+$.i18n.prop('performance.assets.qnszb(%)')+'</th>' +
                        '<th class="sort tr" data-key="tbszPercentage">'+$.i18n.prop('performance.table.szbtb(%)')+'</th>' +
                        '</tr>'
                    );
                    tfootStr = (
                        '<tr>' +
                        '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                        '<td class="tl">' + list.length + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnIncome / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].qnIncome / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].tbsrPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnExpenditure / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].qnExpenditure / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].tbzcPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].jnszPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].qnszPercentage / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].tbszPercentage / list.length) + '</td>' +
                        '</tr>'
                    );
                    for (var i = 0; i < list.length; i++) {
                        tbodyStr += (
                            '<tr>' +
                            '<td class="tc">' + (i + 1) + '</td>' +
                            '<td class="spanTitle" onclick="$containerObj.query(\'' + tag + '\',\'' + list[i].month + '\')">' + fixStr(list[i].monthName) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnIncome / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].qnIncome / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].tbsrPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnExpenditure / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].qnExpenditure / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].tbzcPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].jnszPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].qnszPercentage) + '</td>' +
                            '<td class="tr">' + fix2(list[i].tbszPercentage) + '</td>' +
                            '</tr>'
                        );
                    }
                }
                var table, thead, tbody, tfoot, main;
                if (tag === 'year') {
                    table = $this.yearTable;
                    thead = $this.yearThead;
                    tbody = $this.yearTbody;
                    tfoot = $this.yearTfoot;
                    main = $this.yearMain;
                } else {
                    table = $this.table;
                    thead = $this.thead;
                    tbody = $this.tbody;
                    tfoot = $this.tfoot;
                    main = $this.main;
                }
                thead.html(theadStr);
                tbody.html(tbodyStr);
                tfoot.html(tfootStr);
                /* 排序 */
                // 添加排序图片
                var sort = thead.find('.sort').append('<img src="' + basePath + 'plugins/charts/images/sort.png">').each(function () {
                    if (key === $(this).data().key) { // 根据sorting和key设置排序字段图片
                        $(this).find('img').attr('src', basePath + 'plugins/charts/images/sort_' + (sorting === 'desc' ? 'up' : 'down') + '.png');
                    }
                });
                /* 点击表头重新排序 */
                sort.on('click', function () {
                    var src = $(this).find('img').attr('src');
                    if (src.indexOf('sort_up.png') !== -1) {
                        $containerObj.modalObj.setModal($(this).data().tag, $(this).data().key, 'asc');
                    } else if ((src.indexOf('sort_down.png') !== -1) || (src.indexOf('sort.png') !== -1)) {
                        $containerObj.modalObj.setModal($(this).data().tag, $(this).data().key, 'desc');
                    }
                });
                main.iziModal('open');
                // 延时设置表格首尾固定，防止页面卡死
                setTimeout(function () {
                    // 如果列表长度大于200，则值固定表头表尾，不固定前两列，防止页面卡死
                    if (list.length > 200) {
                        table.tableHeadFixer({'head': true, 'foot': true});
                    } else {
                        table.tableHeadFixer({'left': 2, 'head': true, 'foot': true});
                    }
                    loading(true);
                }, 20);
            }, 20);
        },
        /* 绑定事件 */
        bindEvent: function () {
            var $this = this;
            // 点击详情按钮，设置对应数据，弹出模态框
            $containerObj.main.find('.detail-btn').on('click', function () {
                var tag = $(this).data().tag;
                var key = '';
                var sorting = 'desc';
                if (tag === 'assets') {
                    key = 'amount';
                } else if (tag === 'year') {
                    key = 'month';
                    sorting = 'asc';
                } else {
                    key = 'jnAssetsAmount';
                }
                $this.setModal(tag, key, sorting);
            })
        },
        /* 处理新增、报废、设备的点击 */
        query: function (tag, params, count) {
            if (count > 0) {
                var $this = this;
                loading(function () {
                    params = string2json(params);
                    if (tag === 'income') {
                        $this.queryAssetsTable('assets', $.extend(params, {queryType: 3}));
                        $this.assetsMain.iziModal('setTitle', $.i18n.prop('share.talbe.srsbxq'));
                    } else if (tag === 'expenditure') {
                        $this.queryAssetsTable('assets', $.extend(params, {queryType: 4}));
                        $this.assetsMain.iziModal('setTitle', $.i18n.prop('share.talbe.zcsbxq'));
                    }
                });
            }
        },
        /* 查询设备、新增、报废数据 */
        queryAssetsTable: function (url, params) {
            var $this = this;
            publicAjax(basePath + 'charts/area/cost/' + url, 'post', $.extend({}, $headerObj.searchObj.params, params), function (data) {
                $this.data.count = data.data;
                ($this.data.count.list || []).calTotal().sortByKey('amount');
                $this.setAssetsTable('amount', 'desc');
            }, true);
        },
        /* 设置设备、新增、报废表格数据 */
        setAssetsTable: function (key, sorting) {
            var $this = this,
                theadStr = '',
                tbodyStr = '',
                tfootStr = '',
                list = (this.data.count.list || []).sortByKey(sorting, key);
            loading();
            theadStr = (
                '<tr><th class="tc">#</th>' +
                '<th class="sort tl" data-key="name">'+$.i18n.prop('share.table.head.sbmc')+'</th>' +
                '<th class="sort tl" data-key="firstTypeName">'+$.i18n.prop('share.table.head.sblx')+'</th>' +
                '<th class="sort tl" data-key="hospital">'+$.i18n.prop('share.assets.ssyy')+'</th>' +
                '<th class="sort tl" data-key="department">'+$.i18n.prop('share.assets.ssks')+'</th>' +
                '<th class="sort tl" data-key="manufacturer">'+$.i18n.prop('share.table.head.sbcj')+'</th>' +
                '<th class="sort tl" data-key="sn">'+$.i18n.prop('share.assets.snbh')+'</th>' +
                '<th class="sort tl" data-key="assetsNo">'+$.i18n.prop('share.assets.zcbh')+'</th>' +
                '<th class="sort tr" data-key="amount">'+$.i18n.prop('share.assets.sbje(wy)')+'</th>' +
                '<th class="sort tr" data-key="jnIncome">'+$.i18n.prop('performance.assets.jnsr(wy)')+'</th>' +
                '<th class="sort tr" data-key="qnIncome">'+$.i18n.prop('performance.assets.qnsr(wy)')+'</th>' +
                '<th class="sort tr" data-key="tbsrPercentage">'+$.i18n.prop('performance.assets.srtb(%)')+'</th>' +
                '<th class="sort tr" data-key="jnExpenditure">'+$.i18n.prop('performance.assets.jnzc(wy)')+'</th>' +
                '<th class="sort tr" data-key="qnExpenditure">'+$.i18n.prop('performance.assets.qnzc(wy)')+'</th>' +
                '<th class="sort tr" data-key="tbzcPercentage">'+$.i18n.prop('performance.assets.zctb(%)')+'</th>' +
                '<th class="sort tr" data-key="jnszPercentage">'+$.i18n.prop('performance.assets.jnszb(%)')+'</th>' +
                '<th class="sort tr" data-key="qnszPercentage">'+$.i18n.prop('performance.assets.qnszb(%)')+'</th>' +
                '</tr>'
            );
            tfootStr = (
                '<tr>' +
                '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                '<td class="tl">' + list.length + '</td>' +
                '<td class="tl"></td>' +
                '<td class="tl"></td>' +
                '<td class="tl"></td>' +
                '<td class="tl"></td>' +
                '<td class="tl"></td>' +
                '<td class="tl"></td>' +
                '<td class="tr">' + fix2(list[-1].amount / PRICE_CONVERT) + '</td>' +
                '<td class="tr">' + fix2(list[-1].jnIncome / PRICE_CONVERT) + '</td>' +
                '<td class="tr">' + fix2(list[-1].qnIncome / PRICE_CONVERT) + '</td>' +
                '<td class="tr">' + fix2(list[-1].tbsrPercentage / list.length) + '</td>' +
                '<td class="tr">' + fix2(list[-1].jnExpenditure / PRICE_CONVERT) + '</td>' +
                '<td class="tr">' + fix2(list[-1].qnExpenditure / PRICE_CONVERT) + '</td>' +
                '<td class="tr">' + fix2(list[-1].tbzcPercentage / list.length) + '</td>' +
                '<td class="tr">' + fix2(list[-1].jnszPercentage / list.length) + '</td>' +
                '<td class="tr">' + fix2(list[-1].qnszPercentage / list.length) + '</td>' +
                '</tr>'
            );
            for (var i = 0; i < list.length; i++) {
                tbodyStr += (
                    '<tr>' +
                    '<td class="tc">' + (i + 1) + '</td>' +
                    '<td class="spanTitle" onclick="$containerObj.query(\'assets\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                    '<td class="tl">' + fixStr(list[i].firstTypeName) + '</td>' +
                    '<td class="tl">' + fixStr(list[i].hospitalName) + '</td>' +
                    '<td class="tl">' + fixStr(list[i].departmentName) + '</td>' +
                    '<td class="tl">' + fixStr(list[i].manufacturer) + '</td>' +
                    '<td class="tl">' + fixStr(list[i].sn) + '</td>' +
                    '<td class="tl">' + fixStr(list[i].assetsNo) + '</td>' +
                    '<td class="tr">' + fix2(list[i].amount / PRICE_CONVERT) + '</td>' +
                    '<td class="tr">' + fix2(list[i].jnIncome / PRICE_CONVERT) + '</td>' +
                    '<td class="tr">' + fix2(list[i].qnIncome / PRICE_CONVERT) + '</td>' +
                    '<td class="tr">' + fix2(list[i].tbsrPercentage) + '</td>' +
                    '<td class="tr">' + fix2(list[i].jnExpenditure / PRICE_CONVERT) + '</td>' +
                    '<td class="tr">' + fix2(list[i].qnExpenditure / PRICE_CONVERT) + '</td>' +
                    '<td class="tr">' + fix2(list[i].tbzcPercentage) + '</td>' +
                    '<td class="tr">' + fix2(list[i].jnszPercentage) + '</td>' +
                    '<td class="tr">' + fix2(list[i].qnszPercentage) + '</td>' +
                    '</tr>'
                );
            }
            $this.assetsThead.html(theadStr);
            $this.assetsTbody.html(tbodyStr);
            $this.assetsTfoot.html(tfootStr);
            /* 排序 */
            var sort = $this.assetsThead.find('.sort').append('<img src="' + basePath + 'plugins/charts/images/sort.png">').each(function () {
                if (key === $(this).data().key) {
                    $(this).find('img').attr('src', basePath + 'plugins/charts/images/sort_' + (sorting === 'desc' ? 'up' : 'down') + '.png');
                }
            });
            sort.on('click', function () {
                var src = $(this).find('img').attr('src');
                if (src.indexOf('sort_up.png') !== -1) {
                    $containerObj.modalObj.setAssetsTable($(this).data().key, 'asc');
                } else if ((src.indexOf('sort_down.png') !== -1) || (src.indexOf('sort.png') !== -1)) {
                    $containerObj.modalObj.setAssetsTable($(this).data().key, 'desc');
                }
            });
            $this.assetsMain.iziModal('open');
            setTimeout(function () {
                if (list.length > 200) {
                    $this.assetsTable.tableHeadFixer({'head': true, 'foot': true});
                } else {
                    $this.assetsTable.tableHeadFixer({'left': 2, 'head': true, 'foot': true});
                }
                loading(true);
            }, 20);
        }
    };
});